package cn.lan.generator.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.lan.generator.bean.ProjInfo;

/**
 * 常量类
 *
 * @author 兰平
 * @version 1.0
 * @date 2017-6-5
 */
public class Constant {

    /**
     * 警告消息
     */
    public static final String warnMsg = "warning message： ";

    /**
     * 配置文件路径CONFIG_PATH
     */
    public static final String CONFIG_PATH = "config.properties";
    /**
     * 创建项目地址
     */
    public static final String KEY_CREATE_PROJ_URL = "createProjectUrl";

    /**
     * 模板文件地址
     */
    public static final String KEY_TEMPLATE_DIR = "templateDir";

    /**
     * 数据库类型 DB2
     */
    public static final String DB_TYPE_DB2 = "db2";

    /**
     * 数据库类型 MYSQL
     */
    public static final String DB_TYPE_MYSQL = "mysql";

    /**
     * 数据库类型 SQLSERVER
     */
    public static final String DB_TYPE_SQLSERVER = "sqlserver";

    /**
     * key 默认包
     */
    public static final String KEY_DEFAULT_PACKAGE = "defaultPackage";

    /**
     * key defaultAuthEmail
     */
    public static final String KEY_DEFAULT_AUTH_EMAIL = "defaultAuthEmail";

    /**
     * key basePath
     */
    public static final String KEY_BASE_PATH = "basePath";
    /**
     * key 测试路径
     */
    public static final String KEY_TEST_PATH = "testPath";

    /**
     * key entityPath
     */
    public static final String KEY_ENTITY_PATH = "entityPath";

    /**
     * key utilPath
     */
    public static final String KEY_UTIL_PATH = "commonUtilPath";
    /**
     * key redisPath
     */
    public static final String KEY_REDIS_PATH = "redisPath";

    /**
     * key commonTokenPath
     */
    public static final String KEY_COMMON_TOKEN_PATH = "commonTokenPath";

    /**
     * key commonTokenBeanPath
     */
    public static final String KEY_COMMON_TOKEN_BEAN_PATH = "commonTokenBeanPath";

    /**
     * key commonTokenConfigPath
     */
    public static final String KEY_COMMON_TOKEN_CONFIG_PATH = "commonTokenConfigPath";

    /**
     * key commonTokenManagerPath
     */
    public static final String KEY_COMMON_TOKEN_MANAGER_PATH = "commonTokenManagerPath";

    /**
     * key enumPath
     */
    public static final String KEY_ENUM_PATH = "enumPath";

    /**
     * key voPath
     */
    public static final String KEY_VO_PATH = "voPath";

    /**
     * key annotationPath
     */
    public static final String KEY_ANNOTATION_PATH = "annotationPath";

    /**
     * key filterPath
     */
    public static final String KEY_FILTER_PATH = "filterPath";

    /**
     * key interceptorPath
     */
    public static final String KEY_INTERCEPTOR_PATH = "interceptorPath";

    /**
     * key controllerPath
     */
    public static final String KEY_CONTROLLER_PATH = "controllerPath";

    /**
     * key serverBasePath
     */
    public static final String KEY_SERVER_BASE_PATH = "serverBasePath";

    /**
     * key viewPath
     */
    public static final String KEY_VIEW_CONTROLLER_PATH = "viewControllerPath";

    /**
     * key mappingsPath
     */
    public static final String KEY_MAPPINGS_PATH = "mappingsPath";

    /**
     * key resourcePath
     */
    public static final String KEY_RESOURCE_PATH = "resourcePath";
    
    /**
     * key resource_templates
     */
    public static final String KEY_RESOURCE_TEMPLATES = "resource_templates";

    /**
     * key resource_static
     */
    public static final String KEY_RESOURCE_STATIC = "resource_static";

    /**
     * key serviceImplPath
     */
    public static final String KEY_SERVICE_IMPL_PATH = "serviceImplPath";

    /**
     * key servicePath
     */
    public static final String KEY_SERVICE_PATH = "servicePath";

    /**
     * key commonConfigPath
     */
    public static final String KEY_COMMON_CONFIG_PATH = "commonConfigPath";

    /**
     * key dtoPath
     */
    public static final String KEY_DTO_PATH = "dtoPath";

    /**
     * key listDtoPath
     */
    public static final String KEY_LIST_DTO_PATH = "listDtoPath";

    /**
     * key beanCommonPath
     */
    public static final String KEY_COMMON_BEAN_PATH = "commonBeanPath";

    /**
     * key beanCommonVoPath
     */
    public static final String KEY_COMMON_BEAN_VO_PATH = "commonBeanVoPath";

    /**
     * key commonPath
     */
    public static final String KEY_COMMON_PATH = "commonPath";

    /**
     * key beanCommonDtoPath
     */
    public static final String KEY_COMMON_BEAN_DTO_PATH = "commonBeanDtoPath";

    /**
     * key exceptionPath
     */
    public static final String KEY_EXCEPTION_PATH = "exceptionPath";

    /**
     * key validatePath
     */
    public static final String KEY_VALIDATE_PATH = "validatePath";

    /**
     * key mybatisplusPath
     */
    public static final String KEY_MYBATIS_PLUS_PATH = "mybatisplusPath";

    /**
     * key mapperPath
     */
    public static final String KEY_MAPPER_PATH = "mapperPath";

    /**
     * key access_base_url
     */
    public static final String KEY_ACCESS_BASE_URL = "access_base_url";

    /**
     * key isCreateZIPFile
     */
    public static final String KEY_IS_CREATE_ZIP_FILE = "isCreateZIPFile";

    /**
     * suffix  java
     */
    public static final String FILE_SUFFIX_JAVA = ".java";

    /**
     * suffix  xml
     */
    public static final String FILE_SUFFIX_XML = ".xml";

    /**
     * suffix  zip
     */
    public static final String FILE_SUFFIX_ZIP = ".zip";

    /**
     * config
     */
    public static final String SERVER_CONFIG_PATH = "serverConfigPath";


    /**
     * aspect
     */
    public static final String ASPECT_PATH = "aspectPath";

    /**
     * template
     */
    public static final String TEMPLATE_PATH = "template";

    /**
     * TemplateMapper文件地址
     */
    public static final String TEMPLATE_MAPPER_PATH = TEMPLATE_PATH+"/java/module/mapper/TemplateMapper.java";

    /**
     * TemplateMapper.xml文件地址
     */
    public static final String TEMPLATE_MAPPER_XML_PATH = TEMPLATE_PATH+"/java/module/mapper/xml/TemplateMapper.xml";

    /**
     * TemplateService文件地址
     */
    public static final String TEMPLATE_SERVICE_PATH = TEMPLATE_PATH+"/java/module/service/TemplateService.java";

    /**
     * TemplateServiceImpl文件地址
     */
    public static final String TEMPLATE_SERVICE_IMPL_PATH = TEMPLATE_PATH+"/java/module/service/impl/TemplateServiceImpl.java";

    /**
     * pom_service.xml文件地址
     */
    public static final String TEMPLATE_SERVICE_POM_PATH = TEMPLATE_PATH+"/config/pom_service.xml";

    /**
     * TemplatEntity文件地址
     */
    public static final String TEMPLATE_ENTITY_PATH = TEMPLATE_PATH+"/java/module/entity/TemplateEntity.java";

    /**
     * TemplateEntityDto文件地址
     */
    public static final String TEMPLATE_ENTITY_DTO_PATH = TEMPLATE_PATH+"/java/module/dto/TemplateEntityDto.java";

    /**
     * TemplateEntityListDto文件地址
     */
    public static final String TEMPLATE_ENTITY_LIST_DTO_PATH = TEMPLATE_PATH+"/java/module/dto/list/TemplateEntityListDto.java";

    /**
     * TemplateEntityVo文件地址
     */
    public static final String TEMPLATE_ENTITY_VO_PATH = TEMPLATE_PATH+"/java/module/vo/TemplateEntityVo.java";

    /**
     * TemplateController文件地址
     */
    public static final String TEMPLATE_CONTROLLER_PATH = TEMPLATE_PATH+"/java/controller/TemplateController.java";

    /**
     * EntityViewController文件地址
     */
    public static final String TEMPLATE_VIEW_CONTROLLER_PATH = TEMPLATE_PATH+"/java/controller/view/EntityViewController.java";


    /**
     * 条件like数组
     */
    public static final String [] SQL_LIKE_NAME_ARRAY = new String[]{"name","title","type","phone","identityCard","identityId"};

    /**
     * list查询
     */
    public static final String [] QUERY_LIST_COND_ARRAY = new String[]{"state", "status","code"};

    /**
     * 不需要查询的条件
     */
    public static String[] QUERY_NOT_COND_ARRAY = new String[]{"remark","date","time","json","text","data",
            "latitude","longitude","lat","lng","logo","address","url","path","param","_desc","description","introduce","content",
    "title"};

    public static final String [] SQL_KEYS={"rank","key","before",
            "after","column","from","to","end","start","global","like","min","max","point","time","date",
            "year","month","day","event","do","comment","commit","user","value","name","type","code","range","drop",
            "delete","length","exit","required","select","update","delete","insert","sql","database","driver","host",
            "password","url","port","show","schema","where","in","group","join","left","right","index","primary","having",
            "and","or","not","commit","grant","rollback","revoke","rename","drop","alter","create"
    };

    public static final String IS_TRUE = "true";

    public static final String DEFAULT_SORT_NAME = "create_time";

    public static String getFilePath(ProjInfo projInfo,String moduleName, PathType pathType, String suffixPath) {
        String rootDir = projInfo.getCreateProjectUrl();
        String resourcePath = ConfigUtil.getConfigValue(Constant.KEY_RESOURCE_PATH).replaceAll("/", "\\\\");
        moduleName = ObjectUtil.isEmpty(moduleName)?"":(moduleName+"\\");
        String srcPath = "";
        if (pathType == PathType.basePath) {
            srcPath = moduleName+ ConfigUtil.getConfigValue(Constant.KEY_BASE_PATH).replaceAll("/", "\\\\");
        } else if (pathType == PathType.testPath) {
            srcPath = moduleName+ ConfigUtil.getConfigValue(Constant.KEY_TEST_PATH).replaceAll("/", "\\\\");
        } else if (pathType == PathType.resourcePath) {
            srcPath = moduleName+ ConfigUtil.getConfigValue(Constant.KEY_RESOURCE_PATH).replaceAll("/", "\\\\");
        }else if (pathType == PathType.resource_templates) {
            srcPath = moduleName+resourcePath+ ConfigUtil.getConfigValue(Constant.KEY_RESOURCE_TEMPLATES).replaceAll("/", "\\\\");
        }else if (pathType == PathType.resource_static) {
            srcPath = moduleName+resourcePath+ ConfigUtil.getConfigValue(Constant.KEY_RESOURCE_STATIC).replaceAll("/", "\\\\");
        }else{
            srcPath = moduleName;
        }

        String path = rootDir + projInfo.getProjectName() + "\\" + srcPath + suffixPath;
        return path;
    }

    public enum PathType {
        basePath,
        testPath,
        resourcePath,
        resource_templates,
        resource_static;
    }

}
